from api.jiuchao_login_api import JCLoginApi
from common.assert_tools import common_assert
import pytest

from common.read_json_file import read_json_data
from config import BASE_DIR


class TestJCLoginParams(object):
    # 定义通用测试方法-测试登录接口
    data = read_json_data(BASE_DIR + "/data/login_data.json")

    @pytest.mark.parametrize("desc,req_data,status_code,code,msg", data)
    def test_jiuchao_login(self, desc, req_data, status_code, code,
                           msg):  # 只留第一条登录成功方法，方法名可以自行稍微一改，由test01_login_success改为test_jiuchao_login
        # 准备登录测试数据
        # 调用自己封装的API，获取响应结果
        resp = JCLoginApi.login(req_data)
        # 打印
        print(desc, ":", resp.json())
        # 调用自己封装的断言
        common_assert(resp, status_code, code, msg)

    # # 定义测试方法-手机号未注册
    # def test02_mobile_not_register(self):
    #     # 准备登录测试数据
    #     data = {"mobile": "19811797670", "password": "jxz123456!@#", "category": "0"}
    #     # 调用自己封装的API，获取响应结果
    #     resp = JCLoginApi.login(data)
    #     # 打印
    #     print("手机号未注册:", resp.json())
    #     # 调用自己封装的断言
    #     common_assert(resp, 200, 1004001001, "手机号未注册用户")
    #
    # # 定义测试方法-密码错误
    # def test03_pwd_err(self):
    #     # 准备登录测试数据
    #     data = {"mobile": "19811796705", "password": "jxz123456", "category": "0"}
    #     # 调用自己封装的API，获取响应结果
    #     resp = JCLoginApi.login(data)
    #     # 打印
    #     print("密码错误:", resp.json())
    #     # 调用自己封装的断言
    #     common_assert(resp, 200, 1004003000, "登录失败，账号密码不正确")
    #
    # # 定义方法-手机号为空
    # def test05_mobile_none(self):
    #     data = {"mobile": None, "password": "jxz123456!@#", "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("手机号为空", resp.json())
    #     common_assert(resp, 200, 400, "请求参数不正确:手机号不能为空")
    #
    # # 定义方法-手机号含有字母特殊字符
    # def test06_mobile_contain_letters_characters(self):
    #     data = {"mobile": "19811796@A!", "password": "jxz123456!@#", "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("手机号含有字母特殊字符", resp.json())
    #     common_assert(resp, 200, 400, "请求参数不正确:手机号格式不正确")
    #
    # # 定义方法-手机号10位
    # def test07_mobile_ten(self):
    #     data = {"mobile": "1981179670", "password": "jxz123456!@#", "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("手机号10位", resp.json())
    #     common_assert(resp, 200, 400, "请求参数不正确:手机号格式不正确")
    #
    # # 定义方法-手机号12位
    # def test08_mobile_twelve(self):
    #     data = {"mobile": "198117967055", "password": "jxz123456!@#", "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("手机号12位", resp.json())
    #     common_assert(resp, 200, 400, "请求参数不正确:手机号格式不正确")
    #
    # # 定义方法-密码为空
    # def test09_password_none(self):
    #     data = {"mobile": "19811796705", "password": None, "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("密码为空", resp.json())
    #     common_assert(resp, 200, 400, "请求参数不正确:密码不能为空")
    #
    # # 定义方法-密码含有字母特殊字符
    # def test10_password_contain_letters_characters(self):
    #     data = {"mobile": "19811796705", "password": "jxz123456!@#", "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("密码含有字母特殊字符", resp.json())
    #     common_assert(resp, 200, 0, "")
    #
    # # 定义方法-密码5位
    # def test11_password_five(self):
    #     data = {"mobile": "19811796705", "password": "jxz12", "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("密码5位", resp.json())
    #     common_assert(resp, 200, 400, "密码长度为 6-15 位")
    #
    # # 定义方法-密码16位
    # def test12_password_sixteen(self):
    #     data = {"mobile": "19811796705", "password": "jxz1234567890123", "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("密码16位", resp.json())
    #     common_assert(resp, 200, 400, "密码长度为 6-15 位")
    #
    # # 定义方法-多参abc
    # def test13_more_parameter_abc(self):
    #     data = {"mobile": "19811796705", "password": "jxz123456!@#", "category": "0", "abc": "123"}
    #     resp = JCLoginApi.login(data)
    #     print("多参abc", resp.json())
    #     common_assert(resp, 200, 0, "")
    #
    # # 定义方法-少参mobile
    # def test14_less_parameter_mobile(self):
    #     data = {"password": "jxz123456!@#", "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("少参mobile", resp.json())
    #     common_assert(resp, 200, 400, "请求参数不正确:手机号不能为空")

    # # 定义方法-无参
    # def test15_no_parameter(self):
    #     data = None
    #     resp = JCLoginApi.login(data)
    #     print("无参", resp.json())
    #
    # # 定义方法-修改password为abc
    # def test16_password_update_abc(self):
    #     data = {"mobile": "19811796705", "abc": "jxz123456", "category": "0"}
    #     resp = JCLoginApi.login(data)
    #     print("错误参数", resp.json())
    # 因为无参和错误参数这两个方法的断言有可能是手机号不能为空有可能是密码错误，所以先不要了，因为断言没法弄
